package com.appspot.javametronome.client.view;

import com.appspot.javametronome.client.controller.BpmController;
import com.appspot.javametronome.client.model.Bpm;
import com.appspot.javametronome.client.view.widget.ButtonGroup;
import com.appspot.javametronome.client.view.widget.PlayButton;
import com.appspot.javametronome.client.view.widget.TapInButton;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.ValueBoxBase.TextAlignment;

public class View {
    
    private TextBox bpmField;

    public void setUp(RootPanel root) {

        // Set up widgets
        bpmField = new TextBox();
        bpmField.setAlignment(TextAlignment.RIGHT);
        bpmField.setWidth("30px");
        bpmField.setMaxLength(3);
        bpmField.setText(BpmController.instance.getBpm().getStringValue());

        PlayButton playButton = new PlayButton();
        TapInButton tapButton = new TapInButton();
        new ButtonGroup(playButton, tapButton);

        // TODO layout widgets
        root.add(bpmField);
        root.add(playButton);
        root.add(tapButton);
    }
    
    public void bpmChanged(Bpm bpm) {
        bpmField.setText(bpm.getStringValue());
    }
    
    public double getCurrentBpm() {
        return Double.parseDouble(bpmField.getText());
    }
}
